/*----------------------绑定手势---------------------*/
//位置移动
mc.on("panstart",function(e){
	  mapScale = parseFloat($$('.map-container').data('scale'));
	  //获取现在的坐标
	  mapTop = parseFloat($$('.map-container').data('axisY'));
	  mapLeft = parseFloat($$('.map-container').data('axisX'));
});
mc.on("panmove",function(e){
	  //获取位移
	  var dx = parseFloat(e.deltaX);
	  var dy = parseFloat(e.deltaY);
	  mapdx = dx;
	  mapdy = dy;
	  var cmapleft = mapLeft+dx;
	  var cmaptop  = mapTop+dy;
	  //移动
	  $$('.map-container').transform('translate('+cmapleft+'px,'+cmaptop+'px) scale('+mapScale+')');
	  //console.log(e);
});
mc.on("panend",function(){
	  mapTop  += mapdy;
	  mapLeft += mapdx;
	  $$('.map-container').data('axisY',mapTop);
	  $$('.map-container').data('axisX',mapLeft);
});
//地图缩放
mc.on("pinchstart",function(e){
	  mapTop = parseFloat($$('.map-container').data('axisY'));
	  mapLeft = parseFloat($$('.map-container').data('axisX'));
	  //获取现在比例
	  mapScale = parseFloat($$('.map-container').data('scale'));
});
mc.on("pinchmove",function(e){
	  //获取比例
	  var dscale = e.scale;
	  mapdscale = dscale
	  var cmapscale = mapScale*dscale;
	  //缩放
	  $$('.map-container').transform('translate('+mapLeft+'px,'+mapTop+'px) scale('+cmapscale+')');

});
mc.on("pinchend",function(){
	  mapScale   *= mapdscale;
	  $$('.map-container').data('scale',mapScale);
});
//点击地图
mc.on("tap",function(e){
	  // console.log('page('+e.pointers[0].pageX+';'+e.pointers[0].pageY+')clientX('+e.pointers[0].clientX+','+e.pointers[0].clientY+')'+'tapcenter('+e.center.x+','+e.center.y+')');
	  var scale = parseFloat($$('.map-container').data('scale'));
	  var res = setMarkerPos('.loc-icon',e.center,scale);
	  markerBlock = res.markerblock;
	  markerPos = res.markerpos;
	  markerFloor = res.markerfloor;
	  if(res.markerdisplay){
		  //信息框
		  $$('.routeinfo').hide();
		  $$('#findPath .toolbar').show();
		  //信息框文本
		  var name = '('+res.markerrealpos.x.toString()+','+res.markerrealpos.y.toString()+')';
		  //var name = '('+markerBlock[0].toString()+','+markerBlock[1].toString()+')';
		  $$('#findPath .toolbar .loc-name').html(name);
	  }
});

$$(document).on('change','select[name="startpoint"]',function(){
	var i = parseInt($$(this).val());
	if(i!= 0){
		//网格坐标
		var pos = targetPoint[i].pos;
		//marker位置
		var mleft = (pos[0]+1)*netrectW-netrectW/2-markerSize/2;
		var mtop  = (pos[1]+1)*netrectH-netrectH/2-markerSize;
		var mpos = {'x':mleft,'y':mtop};
		//target name
		var name = targetPoint[i].name;
		//target floor
		var floor = targetPoint[i].floor;
		//切换楼层
		switchFloor(floor);
		//设定起点
		setStartPos(pos,floor,mpos);
	}
	
});

$$(document).on('change','select[name="endpoint"]',function(){
	var i = parseInt($$(this).val());
	if(i != 0){
		//网格坐标
		var pos = targetPoint[i].pos;
		//marker位置
		var mleft = (pos[0]+1)*netrectW-netrectW/2-markerSize/2;
		var mtop  = (pos[1]+1)*netrectH-netrectH/2-markerSize;
		var mpos = {'x':mleft,'y':mtop};
		//target name
		var name = targetPoint[i].name;
		//target floor
		var floor = targetPoint[i].floor;
		//设定终点
		setEndPos2(pos,floor,mpos);
	}
});
  
$$(document).on('click','.startloc',function(){
	setStartPos(markerBlock,markerFloor,markerPos);
});
$$(document).on('click','.endloc',function(){
	setEndPos(markerBlock,markerFloor,markerPos);
});
$$(document).on('click','.walk-icon',function(){
	setAutoNav(markerBlock,markerFloor,markerPos);
});
$$(document).on('click','.switch-btn',function(){
	var floor = $$(this).attr('floor');
	switchFloor(floor);
});
	
 